<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>pytest系列01-pytest安装及基础使用 | 莫伊の测试笔记</title><meta name="keywords" content="Pytest,测试框架"><meta name="author" content="莫伊"><meta name="copyright" content="莫伊"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前言 目前主流的框架：pytest和unittest pytest基于unittest开发，更好用  简介话不多说，直接参考官网（优点一箩筐😂）  简单灵活 支持参数化 支持自动失败重试等处理 插件丰富，支持扩展 …  安装命令行运行 1pip install -U pytest 安装完成后查看版本 123pytest --versionpytest 6.2.3 测试用例设计原则 测试文件名以t">
<meta property="og:type" content="article">
<meta property="og:title" content="pytest系列01-pytest安装及基础使用">
<meta property="og:url" content="https://mooii.gitee.io/2021/10/20/Pytest01/index.html">
<meta property="og:site_name" content="莫伊の测试笔记">
<meta property="og:description" content="前言 目前主流的框架：pytest和unittest pytest基于unittest开发，更好用  简介话不多说，直接参考官网（优点一箩筐😂）  简单灵活 支持参数化 支持自动失败重试等处理 插件丰富，支持扩展 …  安装命令行运行 1pip install -U pytest 安装完成后查看版本 123pytest --versionpytest 6.2.3 测试用例设计原则 测试文件名以t">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5374(20211213-233104).PNG">
<meta property="article:published_time" content="2021-10-20T12:57:05.360Z">
<meta property="article:modified_time" content="2022-05-25T15:02:56.005Z">
<meta property="article:author" content="莫伊">
<meta property="article:tag" content="Pytest">
<meta property="article:tag" content="测试框架">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5374(20211213-233104).PNG"><link rel="shortcut icon" href="https://mooii.oss-cn-shanghai.aliyuncs.com/%E3%83%AA%E3%82%B9%E3%81%AE%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3%E3%81%A7%E3%81%99%E3%81%9F%E3%81%84%E3%80%82.png"><link rel="canonical" href="https://mooii.gitee.io/2021/10/20/Pytest01/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'pytest系列01-pytest安装及基础使用',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-25 23:02:56'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiperstyle.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.min.css" media="defer" onload="this.media='all'"><script async src="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus@latest/lib/carousel-touch.min.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">35</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5374(20211213-233104).PNG')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">莫伊の测试笔记</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">pytest系列01-pytest安装及基础使用</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-10-20T12:57:05.360Z" title="发表于 2021-10-20 20:57:05">2021-10-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-25T15:02:56.005Z" title="更新于 2022-05-25 23:02:56">2022-05-25</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Pytest/">Pytest</a></span></div><div class="meta-secondline"></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><ul>
<li>目前主流的框架：pytest和unittest</li>
<li>pytest基于unittest开发，更好用</li>
</ul>
<h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>话不多说，直接参考<a target="_blank" rel="noopener" href="https://docs.pytest.org/en/6.2.x/">官网</a>（优点一箩筐😂）</p>
<ul>
<li>简单灵活</li>
<li>支持参数化</li>
<li>支持自动失败重试等处理</li>
<li>插件丰富，支持扩展</li>
<li>…</li>
</ul>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><p>命令行运行</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install -U pytest</span><br></pre></td></tr></table></figure>
<p>安装完成后查看版本</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">pytest --version</span><br><span class="line"></span><br><span class="line">pytest 6.2.3</span><br></pre></td></tr></table></figure>
<h2 id="测试用例设计原则"><a href="#测试用例设计原则" class="headerlink" title="测试用例设计原则"></a>测试用例设计原则</h2><ul>
<li>测试文件名以<code>test_</code>开头或者<code>_test</code>结尾</li>
<li>测试函数以<code>test_</code>开头</li>
<li>测试类以<code>test_</code>开头，且不能包含<code>__init__</code>方法</li>
<li>测试方法（测试用例）以<code>test_</code>开头</li>
<li>pytest也可以执行unittest框架写的用例和方法</li>
</ul>
<h2 id="测试用例执行"><a href="#测试用例执行" class="headerlink" title="测试用例执行"></a>测试用例执行</h2><h3 id="运行某个目录下所有的用例"><a href="#运行某个目录下所有的用例" class="headerlink" title="运行某个目录下所有的用例"></a>运行某个目录下所有的用例</h3><p>切换至对应目录下输入<code>pytest</code>即可</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest</span><br></pre></td></tr></table></figure>
<h3 id="运行一个py文件下的用例"><a href="#运行一个py文件下的用例" class="headerlink" title="运行一个py文件下的用例"></a>运行一个py文件下的用例</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest xx.py</span><br></pre></td></tr></table></figure>
<h3 id="运行某个模块下的函数-类-方法"><a href="#运行某个模块下的函数-类-方法" class="headerlink" title="运行某个模块下的函数/类/方法"></a>运行某个模块下的函数/类/方法</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">pytest -v xx.py::TestXXClass::test_method</span><br><span class="line"><span class="comment"># 运行start.py模块里面。测试类中的某个方法</span></span><br><span class="line">pytest start.py::TestClass::test_case1</span><br></pre></td></tr></table></figure>
<h2 id="执行参数"><a href="#执行参数" class="headerlink" title="执行参数"></a>执行参数</h2><h3 id="v-打印详细信息"><a href="#v-打印详细信息" class="headerlink" title="-v 打印详细信息"></a>-v 打印详细信息</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest -v xx.py::TestXXClass::test_method</span><br></pre></td></tr></table></figure>
<h3 id="q-只打印执行结果"><a href="#q-只打印执行结果" class="headerlink" title="-q 只打印执行结果"></a>-q 只打印执行结果</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest -q login.py</span><br></pre></td></tr></table></figure>
<h3 id="s-详细打印"><a href="#s-详细打印" class="headerlink" title="-s 详细打印"></a>-s 详细打印</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest -s login.py</span><br></pre></td></tr></table></figure>
<h3 id="x-遇到错误立即停止测试"><a href="#x-遇到错误立即停止测试" class="headerlink" title="-x 遇到错误立即停止测试"></a>-x 遇到错误立即停止测试</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest -x login.py</span><br></pre></td></tr></table></figure>
<h3 id="k-匹配用例名称"><a href="#k-匹配用例名称" class="headerlink" title="-k 匹配用例名称"></a>-k 匹配用例名称</h3><p>执行测试用例名称包含login的用例</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest -k login login.py</span><br></pre></td></tr></table></figure>
<p>执行用例名称不包含login的用例</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pytest -k <span class="string">&quot;not login&quot;</span> login.py</span><br></pre></td></tr></table></figure>
<p>🤡ATTENTION:</p>
<ul>
<li>用-k根据用例名称排除时，用例名称需加上<code>&quot; &quot;</code></li>
</ul>
<h3 id="m-标记用例"><a href="#m-标记用例" class="headerlink" title="-m 标记用例"></a>-m 标记用例</h3><p>可运行装饰器装饰的测试用例</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 执行标签为login的测试用例</span></span><br><span class="line">pytest -m login</span><br></pre></td></tr></table></figure>
<h2 id="pycharm配置"><a href="#pycharm配置" class="headerlink" title="pycharm配置"></a>pycharm配置</h2><p>UU们，用得最多的还是直接pycharm运行啊！！！</p>
<p>改一下pycharm默认的运行方式🤣🤣🤣</p>
<p><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/20211102214437.png" alt=""></p>
<p><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/20211102214624.png" alt=""></p>
<p>设置完成了之后，可以在对应的测试用例/测试类前看到一个绿色的三角形，可以直接使用pytest的方式去运行用例啦~~~</p>
</article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>pytest系列01-pytest安装及基础使用</h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="https://mooii.gitee.io/2021/10/20/Pytest01/">https://mooii.gitee.io/2021/10/20/Pytest01/</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info"><div class="post-copyright-a"><h>作者</h><div class="post-copyright-cc-info"><h>莫伊</h></div></div><div class="post-copyright-c"><h>发布于</h><div class="post-copyright-cc-info"><h>2021-10-20</h></div></div><div class="post-copyright-u"><h>更新于</h><div class="post-copyright-cc-info"><h>2022-05-25</h></div></div><div class="post-copyright-c"><h>许可协议</h><div class="post-copyright-cc-info"><a class="icon" rel="noopener" target="_blank" title="Creative Commons" href="https://creativecommons.org/"><i class="fab fa-creative-commons"></i></a><a rel="noopener" target="_blank" title="CC BY-NC-SA 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Pytest/">Pytest</a><a class="post-meta__tags" href="/tags/%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6/">测试框架</a></div><div class="post_share"><div class="social-share" data-image="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5374(20211213-233104).PNG" data-sites="weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://mooii.oss-cn-shanghai.aliyuncs.com/20211021204119.png" target="_blank"><img class="post-qr-code-img" src="https://mooii.oss-cn-shanghai.aliyuncs.com/20211021204119.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://mooii.oss-cn-shanghai.aliyuncs.com/20211021204141.png" target="_blank"><img class="post-qr-code-img" src="https://mooii.oss-cn-shanghai.aliyuncs.com/20211021204141.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/2021/11/28/Pytest02/"><img class="prev-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5375(20211213-233124).PNG" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Pytest系列02-断言的用法</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">莫伊</div><div class="author-info__description">幸运交给锦鲤，你只管努力就好</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">35</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/mooii"><i class="https://mooii.oss-cn-shanghai.aliyuncs.com/20211021164956.png"></i><span>我的主页</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">人生有限，接受事与愿违！！！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E4%BB%8B"><span class="toc-number">2.</span> <span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-number">3.</span> <span class="toc-text">安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E7%94%A8%E4%BE%8B%E8%AE%BE%E8%AE%A1%E5%8E%9F%E5%88%99"><span class="toc-number">4.</span> <span class="toc-text">测试用例设计原则</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E7%94%A8%E4%BE%8B%E6%89%A7%E8%A1%8C"><span class="toc-number">5.</span> <span class="toc-text">测试用例执行</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C%E6%9F%90%E4%B8%AA%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%89%80%E6%9C%89%E7%9A%84%E7%94%A8%E4%BE%8B"><span class="toc-number">5.1.</span> <span class="toc-text">运行某个目录下所有的用例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C%E4%B8%80%E4%B8%AApy%E6%96%87%E4%BB%B6%E4%B8%8B%E7%9A%84%E7%94%A8%E4%BE%8B"><span class="toc-number">5.2.</span> <span class="toc-text">运行一个py文件下的用例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C%E6%9F%90%E4%B8%AA%E6%A8%A1%E5%9D%97%E4%B8%8B%E7%9A%84%E5%87%BD%E6%95%B0-%E7%B1%BB-%E6%96%B9%E6%B3%95"><span class="toc-number">5.3.</span> <span class="toc-text">运行某个模块下的函数&#x2F;类&#x2F;方法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%89%A7%E8%A1%8C%E5%8F%82%E6%95%B0"><span class="toc-number">6.</span> <span class="toc-text">执行参数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#v-%E6%89%93%E5%8D%B0%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF"><span class="toc-number">6.1.</span> <span class="toc-text">-v 打印详细信息</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#q-%E5%8F%AA%E6%89%93%E5%8D%B0%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C"><span class="toc-number">6.2.</span> <span class="toc-text">-q 只打印执行结果</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#s-%E8%AF%A6%E7%BB%86%E6%89%93%E5%8D%B0"><span class="toc-number">6.3.</span> <span class="toc-text">-s 详细打印</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#x-%E9%81%87%E5%88%B0%E9%94%99%E8%AF%AF%E7%AB%8B%E5%8D%B3%E5%81%9C%E6%AD%A2%E6%B5%8B%E8%AF%95"><span class="toc-number">6.4.</span> <span class="toc-text">-x 遇到错误立即停止测试</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#k-%E5%8C%B9%E9%85%8D%E7%94%A8%E4%BE%8B%E5%90%8D%E7%A7%B0"><span class="toc-number">6.5.</span> <span class="toc-text">-k 匹配用例名称</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#m-%E6%A0%87%E8%AE%B0%E7%94%A8%E4%BE%8B"><span class="toc-number">6.6.</span> <span class="toc-text">-m 标记用例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#pycharm%E9%85%8D%E7%BD%AE"><span class="toc-number">7.</span> <span class="toc-text">pycharm配置</span></a></li></ol></div></div><div class="card-widget card-recommend-post"><div class="item-headline"><i class="fas fa-dharmachakra"></i><span>相关推荐</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/11/28/Pytest02/" title="Pytest系列02-断言的用法"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5375(20211213-233124).PNG" alt="Pytest系列02-断言的用法"></a><div class="content"><a class="title" href="/2021/11/28/Pytest02/" title="Pytest系列02-断言的用法">Pytest系列02-断言的用法</a><time datetime="2021-11-28" title="发表于 2021-11-28">2021-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/28/pytest04/" title="Pytest系列04-参数化parametrize()的用法"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5372(20211213-233028).PNG" alt="Pytest系列04-参数化parametrize()的用法"></a><div class="content"><a class="title" href="/2021/11/28/pytest04/" title="Pytest系列04-参数化parametrize()的用法">Pytest系列04-参数化parametrize()的用法</a><time datetime="2021-11-28" title="发表于 2021-11-28">2021-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/28/pytest03/" title="Pytest系列03-setup和teardown"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" alt="Pytest系列03-setup和teardown"></a><div class="content"><a class="title" href="/2021/11/28/pytest03/" title="Pytest系列03-setup和teardown">Pytest系列03-setup和teardown</a><time datetime="2021-11-28" title="发表于 2021-11-28">2021-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/28/pytest05/" title="Pytest系列05-yaml数据驱动"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" alt="Pytest系列05-yaml数据驱动"></a><div class="content"><a class="title" href="/2021/11/28/pytest05/" title="Pytest系列05-yaml数据驱动">Pytest系列05-yaml数据驱动</a><time datetime="2021-11-28" title="发表于 2021-11-28">2021-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/28/pytest06/" title="Pytest系列06-标记mark的使用"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" alt="Pytest系列06-标记mark的使用"></a><div class="content"><a class="title" href="/2021/11/28/pytest06/" title="Pytest系列06-标记mark的使用">Pytest系列06-标记mark的使用</a><time datetime="2021-11-28" title="发表于 2021-11-28">2021-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/28/pytest07/" title="Pytest系列07-配置文件pytest.ini的使用"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" alt="Pytest系列07-配置文件pytest.ini的使用"></a><div class="content"><a class="title" href="/2021/11/28/pytest07/" title="Pytest系列07-配置文件pytest.ini的使用">Pytest系列07-配置文件pytest.ini的使用</a><time datetime="2021-11-28" title="发表于 2021-11-28">2021-11-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2022 By 莫伊</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">好好学习🧡天天学习</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><div class="js-pjax"></div><script data-pjax defer src="/js/custom/fixed_card_widget.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><div id="fixedcard-dashboard"><button class="fixedcard-activebtn" type="button" title="用户信息" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-info&quot;,&quot;0&quot;)"><i class="fas fa-address-book"></i></button><button class="fixedcard-activebtn" type="button" title="电子钟" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-clock&quot;,&quot;0&quot;)"><i class="fas fa-cloud-sun"></i></button><button class="fixedcard-activebtn" type="button" title="相关推荐" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-recommend-post&quot;,&quot;0&quot;)"><i class="fas fa-dharmachakra"></i></button><div class="fixedcard-user-avatar fixedcard-activebtn" onclick="RemoveFixedCardWidget()"><img class="fixedcard-user-avatar-img" src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" title="莫伊"></div></div></div><!-- hexo injector body_end start --> <script data-pjax>if(document.getElementById('recent-posts') && location.pathname =='/'){
    
    var parent = document.getElementById('recent-posts');
    var child = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms"></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载swiper')
    parent.insertAdjacentHTML("afterbegin",child)}
     </script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.js"></script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper@0.18/swiper/swiperindex.js"></script>
<style></style><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = 'undefined';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><script data-pjax>
  function butterfly_clock_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_injector_config();
  }
  </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.js"></script><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script><!-- hexo injector body_end end --></body></html>